//
//  AddPayPage.swift
//  Uber
//
//  Created by chen on 16/3/13.
//  Copyright © 2016年 chen. All rights reserved.
//

import UIKit

class AddPayPage: FxBasePage,UITableViewDataSource,UITableViewDelegate {

    
    
    @IBOutlet weak var tableView: UITableView!
    var datas:[PayInfo]!
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "创建支付方式"
        setNavigationItem("Back.png", selector: "goBack", isRight: false)
        setNavigationItem("验证手机号", selector: "doVerify", isRight: true)
        initDatas()
        
        //创建一个重用的单元格
        self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "CellID")
        self.view.addSubview(tableView)
        self.tableView.reloadData()
    }


    func initDatas(){
        var data:PayInfo!
        let dict:[String:String] = [
            "百度钱包":"BaiDuWallet.png",
            "银联":"YinLian.png",
            "支付宝":"AliPay.png",
            "国际信用卡":"CreditCard.png"
        ]
        datas = []
        for (key,value) in dict{
            data = PayInfo()
            data.name = key
            data.icon = value
            datas.append(data)
        }
    }
    override func goBack() {
        self.navigationController?.popViewControllerAnimated(true)
    }
    func doVerify(){
//        let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
//        appDelegate.showHomePage()
        let verify = VerifyPhonePage()
        self.navigationController?.pushViewController(verify, animated: true)
    }
    
    
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       return datas.count
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let identify:String = "CellID"
        let cell = tableView.dequeueReusableCellWithIdentifier(identify, forIndexPath: indexPath)
        let payInfo = datas[indexPath.row]
        cell.textLabel?.text = payInfo.name
        cell.imageView?.image = UIImage(named: payInfo.icon)
        cell.accessoryType = .DisclosureIndicator
        return cell
    }
    
    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let page = YinLianPage()
        self.navigationController?.pushViewController(page, animated: true)
    }
    

}
